
#pragma once

#include <ucontext.h>

namespace dulymoo {

class Fiber
{
public:
    Fiber();
    Fiber(void (*func)(void*), void* arg, unsigned long stack_size=0);
    ~Fiber();

private:
    Fiber(const Fiber&); // unimplemented
    Fiber& operator= (const Fiber&); // unimplemented

public:
    bool SwitchTo(Fiber &from);
    bool SwitchTo();

private:
    static void FiberProc(void*);

private:
    const bool need_recycle_;
    ucontext_t context_;
    void (*const func_)(void*);
    void* const arg_;
};

} // namespace dulymoo

